/**
 * 
 */
package org.jeecg.client;

import org.jeecg.client.tcp.TCPClient;
import org.jeecg.client.ws.WCFClient;

import java.util.HashMap;
import java.util.Map;

/**
 * @author bright
 * 服务器客户端访问工厂对象
 */
class ClientFactory {
    static Map<String, Class> _PROVIDERS = new HashMap<String, Class>();
    static
    {
        _PROVIDERS.put("tcp", TCPClient.class);
        _PROVIDERS.put("wcf", WCFClient.class);
    };
    
    /**
     * 创建服务器客户端接口
     * @param name
     * @param args
     * @return
     * @throws Exception
     */
    public static IBizCommand CreateClient(String name, String args) throws Exception{
    	String providor = args.split(":")[0];
    	if (_PROVIDERS.containsKey(providor))
    		return (IBizCommand) _PROVIDERS.get(providor).getConstructor(String.class, String.class).newInstance(name, args);
    	else
    		throw new Exception(String.format("Unsupport protocol [%s] of server [%s]", providor, name));
    }
}
